;$(function() {
	var facecontent,options = {
		direction : "down",
		liveTime:0,
		align:"left",
		noCloser:false,
		type:"face"
	},index = 0,which;
	$.subscribe('click_showface',__face,false)
	 .subscribe('click_facetab',__tab,false)
	 .subscribe('click_addface',__add,false);
	
	function __face(t,e,action) {
		var $face = $("#jquery-interactive-face");
		if($face.length) {
			$face.toggle();
		} else {
			if(!options.title) {
				facecontent = $("#facecontent").html();
				options.title = $("#facetitle").html();
			}
			$(t).notice(facecontent , options);
			$.publish("click_facetab" , $("#jquery-interactive-face").find("span.ac_facetab").eq(index)[0]);
			if($(t).parent().attr("id") == 'dd_appsec') {
				which = $("#dd_textarea")[0];
			}
		}
	}
	function __tab(t,e,action) {
		var $t = $(t);
		if(!$t.hasClass("facetitlecurrent")) {
			$t.addClass("facetitlecurrent").removeClass("facetitle").siblings().removeClass("facetitlecurrent").addClass("facetitle");
			index = $t.index();
			var ul = $t.closest(".interactive-main").find("div:last ul");
			ul.eq(index).show().siblings().hide();
		}
		$t = null;
	}
	function __add(t,e,action) {
		$.textbox.insertText(which,'[' + $(t).attr("title") + ']');
		$("#jquery-interactive-face").hide();
		$(which).triggerHandler('keyup');
	}
	$(document).click(function(e) {
		var face = $("#jquery-interactive-face");
		if(face.length && e.target && !$.contains(face[0] , e.target) && !$(e.target).is("a.ac_showface")) {
			face.hide();
		}
		face = null;
	});
});